﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>认证中心后台</title>
    <link href="/themes/default/css/login.css" rel="stylesheet" type="text/css" />
    <link href="/themes/default/css/layer.css" rel="stylesheet" type="text/css" />
    <link href="/themes/default/css/item.css" rel="stylesheet" type="text/css" />
    <script src="/js/common/jquery1.6.1.min.js" type="text/javascript"></script>
    <style type="text/css">
    .DropApp{width:100px;}
    </style>
</head>
<body>
<form id="Form1" runat="server">
    <div id="top"></div>
         <div id="container">
        <div id="header"></div>
        <div id="main">
            <div id="main_left"></div>
            <div id="main_middle">
                <div id="main_middle_top">
                    <div id="login">
                        用户名 <asp:textbox ID="txtUserName" runat="server"></asp:textbox><br />
                        密&nbsp;&nbsp;&nbsp;&nbsp;码 <asp:TextBox ID="txtPassWord" MaxLength="25" runat="server" TextMode="Password"></asp:TextBox>
                        
                        <span style="text-align:center">
                         <asp:Label ID="lbMsg" runat="server" Text="" ForeColor="Red"></asp:Label>
                        </span>
                    </div>
                </div>
                <div id="main_middle_bottom">
                    <div id="left"></div>
                    <div id="middle_login">
                        <asp:Button ID="btnLogin" runat="server" CssClass="BtnLogin" OnClientClick="return showmsg();" onclick="btnLogin_Click" />
                        <input type="hidden" id="HidMsg" value="" /> 
                      </div>
                       <div id="middle_reset">
                        <input type="reset" name="BtnReset" value="" id="BtnReset" class="BtnReset" />
                    </div>
                    <div id="right"></div>
                </div>
            </div>
            <div id="main_right"></div>
        </div>
        <div id="footer"></div>
       </div>
    <div id="bottom"></div>
</form>
</body>
</html>
<script type="text/JavaScript">

    function showmsg() {
        $("#<%=lbMsg.ClientID %>").text("");
        var username = $("#<%=txtUserName.ClientID %>").val();
        var psw = $("#<%=txtPassWord.ClientID %>").val();
        var reg = /^\d+(\.\d+)?$/;
        var regtwo = /^[A-Za-z]+$/;

        if (reg.test(psw)) {
            //alert("密码不能为纯数字，请修改为字母+数字组合！");

            $("#spanName").html(username);
            test();
            return false;
        }

        if (regtwo.test(psw)) {
            //alert("密码不能为纯字母，请修改为字母+数字组合！");
            $("#spanName").html(username);
            test();
            return false;
        }

    }

    function test() {
        var username = $("#<%=txtUserName.ClientID %>").val();
        var psw = $("#<%=txtPassWord.ClientID %>").val();
        var reg = /^\d+(\.\d+)?$/;
        var regtwo = /^[A-Za-z]+$/;

        $.getJSON("/handlers/LoginAction.ashx", { temppwd: psw, tempusername: username }, function (data) {
            $.each(data.contents, function (i, item) {
                $("#hideUserID").val(item.Value);
                if ($("#hideUserID").val() != "") {

                    if (reg.test(psw)) {
                        alert("密码不能为纯数字，请修改为字母+数字组合！");
                        $Layer.Reset();
                        $Layer.IsBack = false;
                        $Layer.IsFooter = false;
                        $Layer.Width = 400;
                        $Layer.Title = "修改密码";
                        $Layer.CloseText = "关 闭";
                        $Layer.Content = $("#divLayer").html();
                        $Layer.IsConfirm = true;
                        $Layer.Confirm.Text = "确 定";
                        $Layer.Confirm.Event = ""
                        $Layer.Open();

                    }

                    if (regtwo.test(psw)) {
                        alert("密码不能为纯字母，请修改为字母+数字组合！");
                        $Layer.Reset();
                        $Layer.IsBack = false;
                        $Layer.IsFooter = false;
                        $Layer.Width = 400;
                        $Layer.Title = "修改密码";
                        $Layer.CloseText = "关 闭";
                        $Layer.Content = $("#divLayer").html();
                        $Layer.IsConfirm = true;
                        $Layer.Confirm.Text = "确 定";
                        $Layer.Confirm.Event = ""
                        $Layer.Open();
                    }
                    $("#HidBool").val("");
                }
                else {
                    $("#<%=lbMsg.ClientID %>").text("用户名或密码不正确!");
                    $("#HidBool").val("false");
                }
            });
        });

    }

    function valdata(obj) {
        var str = obj.value;

        $("#HidBool").val("");
        if (str.toString().length > 25) {
            document.getElementById("confirminfo").innerHTML = "用户密码长度不得超过25，请重新输入！";
            //obj.value = "";
            $("#HidBool").val("false");
            return false;
        }
        else {

            var temppwd = $("#txtOldPassword").val();
            var userid = $("#hideUserID").val();

            $("#confirminfo").html("");
            $.getJSON("/handlers/ChangePwd.ashx", { temppwd: temppwd, userid: userid, state: 0 }, function (data) {
                $.each(data.contents, function (i, item) {

                    if (item.Value != "true") {
                        $("#confirminfo").html("用户密码输入不正确，请重新输入");
                        $("#txtOldPassword").val("");
                        $("#HidBool").val("false");
                        return false;
                    }
                    else {
                        $("#HidBool").val("");
                        return;
                    }

                });
            });

        }

    }

    function validatepwdagine(obj) {
        var str = obj.value;

        $("#confirminfo").html("");
        $("#HidBool").val("");
        if (str.toString().length > 25) {
            document.getElementById("confirminfo").innerHTML = "用户密码长度不得超过25，请重新输入！";
            //obj.value = "";
            $("#HidBool").val("false");
            return false;
        }

        if ($("#txtConfirmPassword").val() != $("#txtNewPassword").val()) {
            $("#confirminfo").html("用户新密码输入不一致，请重新输入");
            //obj.value = "";
            $("#HidBool").val("false");
            return false;
        }
        valdatepwdlength(obj);
    }

    function valdatepwdlength(obj) {
        var str = obj.value;

        $("#confirminfo").html("");
        $("#HidBool").val("");
        if (str.toString().length > 25) {
            document.getElementById("confirminfo").innerHTML = "用户密码长度不得超过25，请重新输入！";
            //obj.value = "";
            $("#HidBool").val("false");
            return false;
        }

        var reg = /^\d+(\.\d+)?$/;
        if (reg.test(str)) {
            document.getElementById("confirminfo").innerHTML = "纯数字密码不安全，请修改为字母+数字的组合！";
            //obj.value = "";
            $("#HidBool").val("false");
            return false;
        }
        var regtwo = /^[A-Za-z]+$/;
        if (regtwo.test(str)) {
            document.getElementById("confirminfo").innerHTML = "纯字母密码不安全，请修改为字母+数字的组合！";
            //obj.value = "";
            $("#HidBool").val("false");
            return false;
        }
    }

    function changepwd() {

        var bool = $("#HidBool").val();
        //alert(bool);
        if (bool == "false") {
            return false;
        }
        else {
            var userid = $("#hideUserID").val();

            var newuserpwd = $("#txtNewPassword").val();

            if ($("#txtOldPassword").val().length < 1) {
                $("#confirminfo").html("请输入密码！");
                return false;
            } else if (newuserpwd.length < 1) {
                $("#confirminfo").html("请输入新密码！");
                return false;
            } else if ($("#txtConfirmPassword").val().length < 1) {
                $("#confirminfo").html("请输入确认密码！");
                return false;
            } else if ($("#txtConfirmPassword").val() != $("#txtNewPassword").val()) {
                $("#confirminfo").html("用户新密码输入不一致，请重新输入");
                return false;
            } else {

                $.getJSON("/handlers/ChangePwd.ashx", { temppwd: newuserpwd, userid: userid, state: 1 }, function () {

                    $("#txtOldPassword").val("");
                    $("#txtNewPassword").val("");
                    $("#txtConfirmPassword").val("");
                    alert("修改完毕！");

                });

            }
        }

    }

    function ready() {
        var Height = document.documentElement.scrollHeight;
        var objTop = document.getElementById("top");
        var objBottom = document.getElementById("bottom");
        if (Height > 607) {
            var SubHeight = (Height - 607) / 2;
            objTop.style.height = SubHeight + "px";
            objBottom.style.height = SubHeight + "px";
        }
    }
    ready();
    window.onresize = ready;
</script>
